<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<title>Stock Control</title>
<link href="../docs-assets/Breadcrumbs.css" rel="stylesheet" rev="stylesheet" type="text/css">
		<meta name="viewport" content="width=device-width initial-scale=1">
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta http-equiv="Content-Language" content="en-gb">

<link href="../docs-assets/Contents.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Progress.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Navigation.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Fonts.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Base.css" rel="stylesheet" rev="stylesheet" type="text/css">
<script>
function togglePopup(material_id) {
  var popup = document.getElementById(material_id);
  popup.classList.toggle("show");
}
</script>

<link href="../docs-assets/Popups.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Colours.css" rel="stylesheet" rev="stylesheet" type="text/css">
		
	</head>
	<body class="commentary-font">
		<nav role="navigation">
		<h1><a href="../index.html"><img src="../docs-assets/Inform.png" height=72> </a></h1>
<ul><li><a href="../index.html">home</a></li>
</ul><h2>Compiler</h2><ul>
<li><a href="../structure.html">structure</a></li>
<li><a href="../inbuildn.html">inbuild</a></li>
<li><a href="../inform7n.html">inform7</a></li>
<li><a href="../intern.html">inter</a></li>
<li><a href="../services.html">services</a></li>
<li><a href="../secrets.html">secrets</a></li>
</ul><h2>Other Tools</h2><ul>
<li><a href="../inblorbn.html">inblorb</a></li>
<li><a href="../inform6.html">inform6</a></li>
<li><a href="../inpolicyn.html">inpolicy</a></li>
</ul><h2>Resources</h2><ul>
<li><a href="../extensions.html">extensions</a></li>
<li><a href="../kits.html">kits</a></li>
</ul><h2>Repository</h2><ul>
<li><a href="https://github.com/ganelson/inform"><img src="../docs-assets/github.png" height=0> github</a></li>
</ul><h2>Related Projects</h2><ul>
<li><a href="https://github.com/ganelson/inweb"><img src="../docs-assets/github.png" height=0> inweb</a></li>
<li><a href="https://github.com/ganelson/intest"><img src="../docs-assets/github.png" height=0> intest</a></li>
</ul>
		</nav>
		<main role="main">
		<!-- Weave of 'Stock Control' generated by inweb -->
<div class="breadcrumbs">
    <ul class="crumbs"><li><a href="../index.html">Home</a></li><li><a href="../services.html">Services</a></li><li><a href="index.html">linguistics</a></li><li><a href="index.html#1">Chapter 1: Setting Up</a></li><li><b>Stock Control</b></li></ul></div>
<p class="purpose">To manage the stock of possible linguistic items.</p>

<ul class="toc"><li><a href="1-sc.html#SP10">&#167;10. Small word sets</a></li></ul><hr class="tocbar">

<p class="commentary firstcommentary"><a id="SP1" class="paragraph-anchor"></a><b>&#167;1. </b>Stock items are classified by their categories. There are only a few of
these, each represented by a single instance of:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">typedef</span><span class="plain-syntax"> </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">grammatical_category</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">name</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="identifier-syntax">method_set</span><span class="plain-syntax"> *</span><span class="identifier-syntax">methods</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">number_of_items</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">CLASS_DEFINITION</span>
<span class="plain-syntax">} </span><span class="reserved-syntax">grammatical_category</span><span class="plain-syntax">;</span>
</pre>
<ul class="endnotetexts"><li>The structure grammatical_category is accessed in 2/art, 2/prn and here.</li></ul>
<p class="commentary firstcommentary"><a id="SP2" class="paragraph-anchor"></a><b>&#167;2. </b>The categories form a fixed set. They are each created by their own sections
of code, as called from this function when the module starts up:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Stock::create_categories</span><button class="popup" onclick="togglePopup('usagePopup1')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup1">Usage of <span class="code-font"><span class="function-syntax">Stock::create_categories</span></span>:<br/>Linguistics Module - <a href="1-lm.html#SP3">&#167;3</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">void</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><a href="2-adj.html#SP2" class="function-link"><span class="function-syntax">Adjectives::create_category</span></a><span class="plain-syntax">();</span>
<span class="plain-syntax">    </span><a href="2-art.html#SP4" class="function-link"><span class="function-syntax">Articles::create_category</span></a><span class="plain-syntax">();</span>
<span class="plain-syntax">    </span><a href="2-nns.html#SP6" class="function-link"><span class="function-syntax">Nouns::create_category</span></a><span class="plain-syntax">();</span>
<span class="plain-syntax">    </span><a href="2-prn.html#SP4" class="function-link"><span class="function-syntax">Pronouns::create_category</span></a><span class="plain-syntax">();</span>
<span class="plain-syntax">    </span><a href="3-prp.html#SP2" class="function-link"><span class="function-syntax">Prepositions::create_category</span></a><span class="plain-syntax">();</span>
<span class="plain-syntax">    </span><a href="2-daq.html#SP5" class="function-link"><span class="function-syntax">Quantifiers::create_category</span></a><span class="plain-syntax">();</span>
<span class="plain-syntax">    </span><a href="3-vrb.html#SP2" class="function-link"><span class="function-syntax">Verbs::create_category</span></a><span class="plain-syntax">();</span>
<span class="plain-syntax">    </span><a href="3-vrb.html#SP9" class="function-link"><span class="function-syntax">Verbs::create_forms_category</span></a><span class="plain-syntax">();</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP3" class="paragraph-anchor"></a><b>&#167;3. </b>Those functions in turn each call this creator:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">grammatical_category</span><span class="plain-syntax"> *</span><span class="function-syntax">Stock::new_category</span><button class="popup" onclick="togglePopup('usagePopup2')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup2">Usage of <span class="code-font"><span class="function-syntax">Stock::new_category</span></span>:<br/>Adjectives - <a href="2-adj.html#SP2">&#167;2</a><br/>Articles - <a href="2-art.html#SP4">&#167;4</a><br/>Determiners and Quantifiers - <a href="2-daq.html#SP5">&#167;5</a><br/>Nouns - <a href="2-nns.html#SP6">&#167;6</a><br/>Pronouns - <a href="2-prn.html#SP4">&#167;4</a><br/>Verbs - <a href="3-vrb.html#SP2">&#167;2</a>, <a href="3-vrb.html#SP9">&#167;9</a><br/>Prepositions - <a href="3-prp.html#SP2">&#167;2</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">name</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">grammatical_category</span><span class="plain-syntax"> *</span><span class="identifier-syntax">cat</span><span class="plain-syntax"> = </span><span class="identifier-syntax">CREATE</span><span class="plain-syntax">(</span><span class="reserved-syntax">grammatical_category</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">cat</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">name</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Str::duplicate</span><span class="plain-syntax">(</span><span class="identifier-syntax">name</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">cat</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">methods</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Methods::new_set</span><span class="plain-syntax">();</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">cat</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">number_of_items</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">cat</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP4" class="paragraph-anchor"></a><b>&#167;4. </b>Grammatical categories support only a single method call:
</p>

<pre class="definitions code-font"><span class="definition-keyword">enum</span> <span class="constant-syntax">LOG_GRAMMATICAL_CATEGORY_MTID</span>
</pre>
<pre class="displayed-code all-displayed-code code-font">
<span class="identifier-syntax">VOID_METHOD_TYPE</span><span class="plain-syntax">(</span><span class="constant-syntax">LOG_GRAMMATICAL_CATEGORY_MTID</span><span class="plain-syntax">, </span><span class="reserved-syntax">grammatical_category</span><span class="plain-syntax"> *</span><span class="identifier-syntax">cat</span><span class="plain-syntax">,</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">general_pointer</span><span class="plain-syntax"> </span><span class="identifier-syntax">data</span><span class="plain-syntax">)</span>
</pre>
<p class="commentary firstcommentary"><a id="SP5" class="paragraph-anchor"></a><b>&#167;5. </b>The stock is essentially a big inventory of items, each represented by an
instance of the following:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">typedef</span><span class="plain-syntax"> </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">linguistic_stock_item</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">grammatical_category</span><span class="plain-syntax"> *</span><span class="identifier-syntax">category</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="identifier-syntax">general_pointer</span><span class="plain-syntax"> </span><span class="identifier-syntax">data</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">CLASS_DEFINITION</span>
<span class="plain-syntax">} </span><span class="reserved-syntax">linguistic_stock_item</span><span class="plain-syntax">;</span>
</pre>
<ul class="endnotetexts"><li>The structure linguistic_stock_item is accessed in 2/adj, 2/art, 3/vrb and here.</li></ul>
<p class="commentary firstcommentary"><a id="SP6" class="paragraph-anchor"></a><b>&#167;6. </b>A flat array is maintained of the entire stock, so that they can be efficiently
looked up by their allocation numbers:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">linguistic_stock_item</span><span class="plain-syntax"> **</span><span class="identifier-syntax">flat_array_of_stock</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">flat_array_of_stock_extent</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>

<span class="reserved-syntax">linguistic_stock_item</span><span class="plain-syntax"> *</span><span class="function-syntax">Stock::new</span><button class="popup" onclick="togglePopup('usagePopup3')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup3">Usage of <span class="code-font"><span class="function-syntax">Stock::new</span></span>:<br/>Adjectives - <a href="2-adj.html#SP3">&#167;3</a><br/>Articles - <a href="2-art.html#SP4">&#167;4</a><br/>Determiners and Quantifiers - <a href="2-daq.html#SP12">&#167;12</a><br/>Nouns - <a href="2-nns.html#SP8">&#167;8</a><br/>Pronouns - <a href="2-prn.html#SP4">&#167;4</a><br/>Verbs - <a href="3-vrb.html#SP3">&#167;3</a>, <a href="3-vrb.html#SP12_1">&#167;12.1</a><br/>Prepositions - <a href="3-prp.html#SP6">&#167;6</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">grammatical_category</span><span class="plain-syntax"> *</span><span class="identifier-syntax">cat</span><span class="plain-syntax">, </span><span class="identifier-syntax">general_pointer</span><span class="plain-syntax"> </span><span class="identifier-syntax">data</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">linguistic_stock_item</span><span class="plain-syntax"> *</span><span class="identifier-syntax">item</span><span class="plain-syntax"> = </span><span class="identifier-syntax">CREATE</span><span class="plain-syntax">(</span><span class="reserved-syntax">linguistic_stock_item</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">item</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">category</span><span class="plain-syntax"> = </span><span class="identifier-syntax">cat</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">item</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">data</span><span class="plain-syntax"> = </span><span class="identifier-syntax">data</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">cat</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">number_of_items</span><span class="plain-syntax">++;</span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="1-sc.html#SP6_1" class="named-paragraph-link"><span class="named-paragraph">Expand the stock array if it has run out of space</span><span class="named-paragraph-number">6.1</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">flat_array_of_stock</span><span class="plain-syntax">[</span><span class="identifier-syntax">item</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">allocation_id</span><span class="plain-syntax">] = </span><span class="identifier-syntax">item</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LOGIF</span><span class="plain-syntax">(</span><span class="identifier-syntax">LINGUISTIC_STOCK</span><span class="plain-syntax">, </span><span class="string-syntax">"Added to stock: "</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Log::aspect_switched_on</span><span class="plain-syntax">(</span><span class="constant-syntax">LINGUISTIC_STOCK_DA</span><span class="plain-syntax">)) </span><a href="1-sc.html#SP7" class="function-link"><span class="function-syntax">Stock::log</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">item</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">item</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP6_1" class="paragraph-anchor"></a><b>&#167;6.1. </b>Note that the array starts empty, so this will happen the first time a stock
item is created.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Expand the stock array if it has run out of space</span><span class="named-paragraph-number">6.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">NUMBER_CREATED</span><span class="plain-syntax">(</span><span class="reserved-syntax">linguistic_stock_item</span><span class="plain-syntax">) &gt; </span><span class="identifier-syntax">flat_array_of_stock_extent</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">new_fa_extent</span><span class="plain-syntax"> = </span><span class="constant-syntax">4</span><span class="plain-syntax">*</span><span class="identifier-syntax">flat_array_of_stock_extent</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">new_fa_extent</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="identifier-syntax">new_fa_extent</span><span class="plain-syntax"> = </span><span class="constant-syntax">2048</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">linguistic_stock_item</span><span class="plain-syntax"> **</span><span class="identifier-syntax">new_fa</span><span class="plain-syntax"> =</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">Memory::calloc</span><span class="plain-syntax">(</span><span class="identifier-syntax">new_fa_extent</span><span class="plain-syntax">, </span><span class="reserved-syntax">sizeof</span><span class="plain-syntax">(</span><span class="reserved-syntax">linguistic_stock_item</span><span class="plain-syntax"> *), </span><span class="constant-syntax">STOCK_MREASON</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax">=0; </span><span class="identifier-syntax">i</span><span class="plain-syntax">&lt;</span><span class="identifier-syntax">new_fa_extent</span><span class="plain-syntax">; </span><span class="identifier-syntax">i</span><span class="plain-syntax">++)</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">i</span><span class="plain-syntax"> &lt; </span><span class="identifier-syntax">flat_array_of_stock_extent</span><span class="plain-syntax">)</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">new_fa</span><span class="plain-syntax">[</span><span class="identifier-syntax">i</span><span class="plain-syntax">] = </span><span class="identifier-syntax">flat_array_of_stock</span><span class="plain-syntax">[</span><span class="identifier-syntax">i</span><span class="plain-syntax">];</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">else</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">new_fa</span><span class="plain-syntax">[</span><span class="identifier-syntax">i</span><span class="plain-syntax">] = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">flat_array_of_stock</span><span class="plain-syntax">)</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">Memory::I7_array_free</span><span class="plain-syntax">(</span><span class="identifier-syntax">flat_array_of_stock</span><span class="plain-syntax">, </span><span class="constant-syntax">STOCK_MREASON</span><span class="plain-syntax">,</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">flat_array_of_stock_extent</span><span class="plain-syntax">, </span><span class="reserved-syntax">sizeof</span><span class="plain-syntax">(</span><span class="reserved-syntax">linguistic_stock_item</span><span class="plain-syntax"> *));</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">flat_array_of_stock</span><span class="plain-syntax"> = </span><span class="identifier-syntax">new_fa</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">flat_array_of_stock_extent</span><span class="plain-syntax"> = </span><span class="identifier-syntax">new_fa_extent</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="1-sc.html#SP6">&#167;6</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP7" class="paragraph-anchor"></a><b>&#167;7. </b>What can we do with the stock? Well, we can log it, which is useful for
diagnostics and the woven form of this module, if nothing else.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Stock::log</span><button class="popup" onclick="togglePopup('usagePopup4')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup4">Usage of <span class="code-font"><span class="function-syntax">Stock::log</span></span>:<br/><a href="1-sc.html#SP6">&#167;6</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">linguistic_stock_item</span><span class="plain-syntax"> *</span><span class="identifier-syntax">item</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LOG</span><span class="plain-syntax">(</span><span class="string-syntax">"%S: "</span><span class="plain-syntax">, </span><span class="identifier-syntax">item</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">category</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">name</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">VOID_METHOD_CALL</span><span class="plain-syntax">(</span><span class="identifier-syntax">item</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">category</span><span class="plain-syntax">, </span><span class="constant-syntax">LOG_GRAMMATICAL_CATEGORY_MTID</span><span class="plain-syntax">, </span><span class="identifier-syntax">item</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">data</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LOG</span><span class="plain-syntax">(</span><span class="string-syntax">"\n"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Stock::log_all</span><span class="plain-syntax">(</span><span class="reserved-syntax">void</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">grammatical_category</span><span class="plain-syntax"> *</span><span class="identifier-syntax">cat</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LOOP_OVER</span><span class="plain-syntax">(</span><span class="identifier-syntax">cat</span><span class="plain-syntax">, </span><span class="reserved-syntax">grammatical_category</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">LOG</span><span class="plain-syntax">(</span><span class="string-syntax">"%S: %d item%s\n"</span><span class="plain-syntax">, </span><span class="identifier-syntax">cat</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">name</span><span class="plain-syntax">, </span><span class="identifier-syntax">cat</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">number_of_items</span><span class="plain-syntax">,</span>
<span class="plain-syntax">            (</span><span class="identifier-syntax">cat</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">number_of_items</span><span class="plain-syntax">==1)?</span><span class="string-syntax">""</span><span class="plain-syntax">:</span><span class="string-syntax">"s"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LOG</span><span class="plain-syntax">(</span><span class="string-syntax">"total in all categories: %d\n\n"</span><span class="plain-syntax">, </span><span class="identifier-syntax">NUMBER_CREATED</span><span class="plain-syntax">(</span><span class="reserved-syntax">linguistic_stock_item</span><span class="plain-syntax">));</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">linguistic_stock_item</span><span class="plain-syntax"> *</span><span class="identifier-syntax">item</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LOOP_OVER</span><span class="plain-syntax">(</span><span class="identifier-syntax">cat</span><span class="plain-syntax">, </span><span class="reserved-syntax">grammatical_category</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">LOOP_OVER</span><span class="plain-syntax">(</span><span class="identifier-syntax">item</span><span class="plain-syntax">, </span><span class="reserved-syntax">linguistic_stock_item</span><span class="plain-syntax">)</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">item</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">category</span><span class="plain-syntax"> == </span><span class="identifier-syntax">cat</span><span class="plain-syntax">)</span>
<span class="plain-syntax">                </span><a href="1-sc.html#SP7" class="function-link"><span class="function-syntax">Stock::log</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">item</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">LOG</span><span class="plain-syntax">(</span><span class="string-syntax">"\n"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP8" class="paragraph-anchor"></a><b>&#167;8. </b>The stock inventory can also be used to make references. Using the stock
ID number (plus 1) as the reference ID of a linguistic constant reference,
we can effectively have a single <span class="extract"><span class="extract-syntax">int</span></span> value refer to a stock item together
with any combination of gender, person, number, voice, case, tense, and sense.
The "plus 1" is so that a reference ID of zeri can mean "no item".
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="identifier-syntax">lcon_ti</span><span class="plain-syntax"> </span><span class="function-syntax">Stock::to_lcon</span><button class="popup" onclick="togglePopup('usagePopup5')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup5">Usage of <span class="code-font"><span class="function-syntax">Stock::to_lcon</span></span>:<br/>Articles - <a href="2-art.html#SP11">&#167;11</a><br/>Pronouns - <a href="2-prn.html#SP7">&#167;7</a><br/>Verbs - <a href="3-vrb.html#SP2">&#167;2</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">linguistic_stock_item</span><span class="plain-syntax"> *</span><span class="identifier-syntax">item</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">Lcon::of_id</span><span class="plain-syntax">(1 + </span><span class="identifier-syntax">item</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">allocation_id</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">linguistic_stock_item</span><span class="plain-syntax"> *</span><span class="function-syntax">Stock::from_lcon</span><button class="popup" onclick="togglePopup('usagePopup6')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup6">Usage of <span class="code-font"><span class="function-syntax">Stock::from_lcon</span></span>:<br/>Adjectives - <a href="2-adj.html#SP2">&#167;2</a><br/>Articles - <a href="2-art.html#SP5">&#167;5</a><br/>Verbs - <a href="3-vrb.html#SP2">&#167;2</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">lcon_ti</span><span class="plain-syntax"> </span><span class="identifier-syntax">l</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">id</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Lcon::get_id</span><span class="plain-syntax">(</span><span class="identifier-syntax">l</span><span class="plain-syntax">) - </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">id</span><span class="plain-syntax"> &lt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) || (</span><span class="identifier-syntax">id</span><span class="plain-syntax"> &gt;= </span><span class="identifier-syntax">flat_array_of_stock_extent</span><span class="plain-syntax">)) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">flat_array_of_stock</span><span class="plain-syntax">[</span><span class="identifier-syntax">id</span><span class="plain-syntax">];</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP9" class="paragraph-anchor"></a><b>&#167;9. </b>Grammatical usages.
Consider nouns, for example. In many languages, declensions do not distinguish
cases fully. In English, the accusative and nominative form of almost every
noun are the same. So it would not be possible for this object to say for
sure what case was used &mdash; for example, the lexicon can't know that the
use of "Jane" in the sentences "Peter knows Jane" and "Jane knows Peter" has
a different case in those sentences: it's only looking at the word itself,
and can't know the wider context. If we parse the word "Jane" the best we can
do is say "it's Jane, in either the nominative or accusative case".
</p>

<p class="commentary">More inflected languages make for more interesting examples here. In German,
for example, "Tische" could be any of the nominative, accusative or genitive
plurals of "Tisch", table, but "Tischen" can only be the dative plural.
</p>

<p class="commentary">The following object represents awkward disjunctions like "either the nominative
or accusative case".
</p>

<pre class="definitions code-font"><span class="definition-keyword">define</span> <span class="constant-syntax">MAX_GU_FORMS</span><span class="plain-syntax"> </span><span class="constant-syntax">2</span><span class="plain-syntax">*</span><span class="identifier-syntax">MAX_GRAMMATICAL_CASES</span>
</pre>
<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">typedef</span><span class="plain-syntax"> </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">grammatical_usage</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">linguistic_stock_item</span><span class="plain-syntax"> *</span><span class="identifier-syntax">used</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">NATURAL_LANGUAGE_WORDS_TYPE</span><span class="plain-syntax"> *</span><span class="identifier-syntax">language</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">no_possible_forms</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">lcon_ti</span><span class="plain-syntax"> </span><span class="identifier-syntax">possible_forms</span><span class="plain-syntax">[</span><span class="constant-syntax">MAX_GU_FORMS</span><span class="plain-syntax">];</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">CLASS_DEFINITION</span>
<span class="plain-syntax">} </span><span class="reserved-syntax">grammatical_usage</span><span class="plain-syntax">;</span>

<span class="reserved-syntax">grammatical_usage</span><span class="plain-syntax"> *</span><span class="function-syntax">Stock::new_usage</span><button class="popup" onclick="togglePopup('usagePopup7')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup7">Usage of <span class="code-font"><span class="function-syntax">Stock::new_usage</span></span>:<br/>Articles - <a href="2-art.html#SP11">&#167;11</a><br/>Nouns - <a href="2-nns.html#SP11_1">&#167;11.1</a><br/>Pronouns - <a href="2-prn.html#SP6">&#167;6</a>, <a href="2-prn.html#SP7">&#167;7</a><br/>Verb Usages - <a href="3-vu.html#SP7_1_3">&#167;7.1.3</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">linguistic_stock_item</span><span class="plain-syntax"> *</span><span class="identifier-syntax">item</span><span class="plain-syntax">, </span><span class="identifier-syntax">NATURAL_LANGUAGE_WORDS_TYPE</span><span class="plain-syntax"> *</span><span class="identifier-syntax">L</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">grammatical_usage</span><span class="plain-syntax"> *</span><span class="identifier-syntax">gu</span><span class="plain-syntax"> = </span><span class="identifier-syntax">CREATE</span><span class="plain-syntax">(</span><span class="reserved-syntax">grammatical_usage</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">gu</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">used</span><span class="plain-syntax"> = </span><span class="identifier-syntax">item</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">gu</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">language</span><span class="plain-syntax"> = </span><span class="identifier-syntax">L</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">gu</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">no_possible_forms</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">gu</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Stock::add_form_to_usage</span><button class="popup" onclick="togglePopup('usagePopup8')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup8">Usage of <span class="code-font"><span class="function-syntax">Stock::add_form_to_usage</span></span>:<br/>Articles - <a href="2-art.html#SP11">&#167;11</a><br/>Nouns - <a href="2-nns.html#SP11_1">&#167;11.1</a><br/>Pronouns - <a href="2-prn.html#SP7">&#167;7</a><br/>Verb Usages - <a href="3-vu.html#SP7_1_3">&#167;7.1.3</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">grammatical_usage</span><span class="plain-syntax"> *</span><span class="identifier-syntax">gu</span><span class="plain-syntax">, </span><span class="identifier-syntax">lcon_ti</span><span class="plain-syntax"> </span><span class="identifier-syntax">f</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">gu</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">used</span><span class="plain-syntax">) </span><span class="identifier-syntax">f</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Lcon::set_id</span><span class="plain-syntax">(</span><span class="identifier-syntax">f</span><span class="plain-syntax">, </span><span class="constant-syntax">1</span><span class="plain-syntax"> + </span><span class="identifier-syntax">gu</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">used</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">allocation_id</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">gu</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">no_possible_forms</span><span class="plain-syntax"> &gt;= </span><span class="constant-syntax">MAX_GU_FORMS</span><span class="plain-syntax">) </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"too many forms"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">gu</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">possible_forms</span><span class="plain-syntax">[</span><span class="identifier-syntax">gu</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">no_possible_forms</span><span class="plain-syntax">++] = </span><span class="identifier-syntax">f</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>

<span class="identifier-syntax">lcon_ti</span><span class="plain-syntax"> </span><span class="function-syntax">Stock::first_form_in_usage</span><button class="popup" onclick="togglePopup('usagePopup9')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup9">Usage of <span class="code-font"><span class="function-syntax">Stock::first_form_in_usage</span></span>:<br/>Verb Usages - <a href="3-vu.html#SP12">&#167;12</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">grammatical_usage</span><span class="plain-syntax"> *</span><span class="identifier-syntax">gu</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">gu</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">no_possible_forms</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"unformed usage"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">gu</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">possible_forms</span><span class="plain-syntax">[0];</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Stock::write_usage</span><button class="popup" onclick="togglePopup('usagePopup10')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup10">Usage of <span class="code-font"><span class="function-syntax">Stock::write_usage</span></span>:<br/>Articles - <a href="2-art.html#SP3">&#167;3</a><br/>Nouns - <a href="2-nns.html#SP5">&#167;5</a><br/>Pronouns - <a href="2-prn.html#SP3">&#167;3</a><br/>Verb Usages - <a href="3-vu.html#SP2">&#167;2</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">OUTPUT_STREAM</span><span class="plain-syntax">, </span><span class="reserved-syntax">grammatical_usage</span><span class="plain-syntax"> *</span><span class="identifier-syntax">gu</span><span class="plain-syntax">, </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">desiderata</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">gu</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">no_possible_forms</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"&lt;unformed usage&gt;"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Lcon::write_set</span><span class="plain-syntax">(</span><span class="identifier-syntax">OUT</span><span class="plain-syntax">, </span><span class="identifier-syntax">gu</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">possible_forms</span><span class="plain-syntax">, </span><span class="identifier-syntax">gu</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">no_possible_forms</span><span class="plain-syntax">, </span><span class="identifier-syntax">desiderata</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="function-syntax">Stock::usage_might_be_singular</span><span class="plain-syntax">(</span><span class="reserved-syntax">grammatical_usage</span><span class="plain-syntax"> *</span><span class="identifier-syntax">gu</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">gu</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax">=0; </span><span class="identifier-syntax">i</span><span class="function-syntax">&lt;gu-&gt;</span><span class="element-syntax">no_possible_forms</span><span class="plain-syntax">; </span><span class="identifier-syntax">i</span><span class="plain-syntax">++)</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Lcon::get_number</span><span class="plain-syntax">(</span><span class="identifier-syntax">gu</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">possible_forms</span><span class="plain-syntax">[</span><span class="identifier-syntax">i</span><span class="plain-syntax">]) == </span><span class="identifier-syntax">SINGULAR_NUMBER</span><span class="plain-syntax">)</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="function-syntax">Stock::usage_might_be_third_person</span><span class="plain-syntax">(</span><span class="reserved-syntax">grammatical_usage</span><span class="plain-syntax"> *</span><span class="identifier-syntax">gu</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">gu</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax">=0; </span><span class="identifier-syntax">i</span><span class="function-syntax">&lt;gu-&gt;</span><span class="element-syntax">no_possible_forms</span><span class="plain-syntax">; </span><span class="identifier-syntax">i</span><span class="plain-syntax">++)</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Lcon::get_person</span><span class="plain-syntax">(</span><span class="identifier-syntax">gu</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">possible_forms</span><span class="plain-syntax">[</span><span class="identifier-syntax">i</span><span class="plain-syntax">]) == </span><span class="identifier-syntax">THIRD_PERSON</span><span class="plain-syntax">)</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<ul class="endnotetexts"><li>The structure grammatical_usage is accessed in 2/art, 2/prn and here.</li></ul>
<p class="commentary firstcommentary"><a id="SP10" class="paragraph-anchor"></a><b>&#167;10. Small word sets.</b>Sometimes we want a very fast way to parse a single word to see if it belongs
to a small set of possibilities &mdash; for example, to see if it is a pronoun.
If there are very few such, even using Preform is unnecessary overhead. The
following is a lightweight alternative:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">typedef</span><span class="plain-syntax"> </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">small_word_set</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">extent</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">used</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="identifier-syntax">vocabulary_entry</span><span class="plain-syntax"> **</span><span class="identifier-syntax">word_ve</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">void</span><span class="plain-syntax"> **</span><span class="identifier-syntax">results</span><span class="plain-syntax">;</span>

<span class="plain-syntax">    </span><span class="identifier-syntax">CLASS_DEFINITION</span>
<span class="plain-syntax">} </span><span class="reserved-syntax">small_word_set</span><span class="plain-syntax">;</span>
</pre>
<ul class="endnotetexts"><li>The structure small_word_set is accessed in 2/art, 2/prn and here.</li></ul>
<p class="commentary firstcommentary"><a id="SP11" class="paragraph-anchor"></a><b>&#167;11. </b>Small word sets do not expand: they must be created large enough. But really,
if we expect them to contain more than about 20 words at the outside, then
we ought to be using standard Preform nonterminals instead.
</p>

<p class="commentary">Small word sets are, however, initially empty &mdash; i.e., no capacity is used.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">small_word_set</span><span class="plain-syntax"> *</span><span class="function-syntax">Stock::new_sws</span><button class="popup" onclick="togglePopup('usagePopup11')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup11">Usage of <span class="code-font"><span class="function-syntax">Stock::new_sws</span></span>:<br/>Articles - <a href="2-art.html#SP10">&#167;10</a><br/>Pronouns - <a href="2-prn.html#SP6">&#167;6</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">capacity</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">small_word_set</span><span class="plain-syntax"> *</span><span class="identifier-syntax">sws</span><span class="plain-syntax"> = </span><span class="identifier-syntax">CREATE</span><span class="plain-syntax">(</span><span class="reserved-syntax">small_word_set</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">sws</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">used</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">sws</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">extent</span><span class="plain-syntax"> = </span><span class="identifier-syntax">capacity</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">sws</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">word_ve</span><span class="plain-syntax"> = (</span><span class="identifier-syntax">vocabulary_entry</span><span class="plain-syntax"> **)</span>
<span class="plain-syntax">        (</span><span class="identifier-syntax">Memory::calloc</span><span class="plain-syntax">(</span><span class="identifier-syntax">sws</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">extent</span><span class="plain-syntax">, </span><span class="reserved-syntax">sizeof</span><span class="plain-syntax">(</span><span class="identifier-syntax">vocabulary_entry</span><span class="plain-syntax"> *), </span><span class="constant-syntax">SWS_MREASON</span><span class="plain-syntax">));</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">sws</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">results</span><span class="plain-syntax"> = (</span><span class="reserved-syntax">void</span><span class="plain-syntax"> **)</span>
<span class="plain-syntax">        (</span><span class="identifier-syntax">Memory::calloc</span><span class="plain-syntax">(</span><span class="identifier-syntax">sws</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">extent</span><span class="plain-syntax">, </span><span class="reserved-syntax">sizeof</span><span class="plain-syntax">(</span><span class="reserved-syntax">void</span><span class="plain-syntax"> *), </span><span class="constant-syntax">SWS_MREASON</span><span class="plain-syntax">));</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">sws</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP12" class="paragraph-anchor"></a><b>&#167;12. </b>The following adds a word.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> *</span><span class="function-syntax">Stock::find_in_sws</span><button class="popup" onclick="togglePopup('usagePopup12')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup12">Usage of <span class="code-font"><span class="function-syntax">Stock::find_in_sws</span></span>:<br/>Articles - <a href="2-art.html#SP11">&#167;11</a>, <a href="2-art.html#SP12">&#167;12</a><br/>Pronouns - <a href="2-prn.html#SP7">&#167;7</a>, <a href="2-prn.html#SP8">&#167;8</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">small_word_set</span><span class="plain-syntax"> *</span><span class="identifier-syntax">sws</span><span class="plain-syntax">, </span><span class="identifier-syntax">vocabulary_entry</span><span class="plain-syntax"> *</span><span class="identifier-syntax">ve</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax">=0; </span><span class="identifier-syntax">i</span><span class="function-syntax">&lt;sws-&gt;</span><span class="element-syntax">used</span><span class="plain-syntax">; </span><span class="identifier-syntax">i</span><span class="plain-syntax">++)</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ve</span><span class="plain-syntax"> == </span><span class="identifier-syntax">sws</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">word_ve</span><span class="plain-syntax">[</span><span class="identifier-syntax">i</span><span class="plain-syntax">])</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">sws</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">results</span><span class="plain-syntax">[</span><span class="identifier-syntax">i</span><span class="plain-syntax">];</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Stock::add_to_sws</span><button class="popup" onclick="togglePopup('usagePopup13')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup13">Usage of <span class="code-font"><span class="function-syntax">Stock::add_to_sws</span></span>:<br/>Articles - <a href="2-art.html#SP11">&#167;11</a><br/>Pronouns - <a href="2-prn.html#SP7">&#167;7</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">small_word_set</span><span class="plain-syntax"> *</span><span class="identifier-syntax">sws</span><span class="plain-syntax">, </span><span class="identifier-syntax">vocabulary_entry</span><span class="plain-syntax"> *</span><span class="identifier-syntax">ve</span><span class="plain-syntax">, </span><span class="reserved-syntax">void</span><span class="plain-syntax"> *</span><span class="identifier-syntax">res</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">sws</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">used</span><span class="plain-syntax"> &gt;= </span><span class="identifier-syntax">sws</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">extent</span><span class="plain-syntax">) </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"small word set exhausted"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">sws</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">word_ve</span><span class="plain-syntax">[</span><span class="identifier-syntax">sws</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">used</span><span class="plain-syntax">] = </span><span class="identifier-syntax">ve</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">sws</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">results</span><span class="plain-syntax">[</span><span class="identifier-syntax">sws</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">used</span><span class="plain-syntax">] = </span><span class="identifier-syntax">res</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">sws</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">used</span><span class="plain-syntax">++;</span>
<span class="plain-syntax">}</span>
</pre>
<nav role="progress"><div class="progresscontainer">
    <ul class="progressbar"><li class="progressprev"><a href="1-dgr.html">&#10094;</a></li><li class="progresschapter"><a href="P-wtmd.html">P</a></li><li class="progresscurrentchapter">1</li><li class="progresssection"><a href="1-lm.html">lm</a></li><li class="progresssection"><a href="1-dgr.html">dgr</a></li><li class="progresscurrent">sc</li><li class="progresssection"><a href="1-cao.html">cao</a></li><li class="progresschapter"><a href="2-adj.html">2</a></li><li class="progresschapter"><a href="3-vrb.html">3</a></li><li class="progresschapter"><a href="4-np.html">4</a></li><li class="progressnext"><a href="1-cao.html">&#10095;</a></li></ul></div>
</nav><!-- End of weave -->

		</main>
	</body>
</html>

